<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

	<head>
		<style type="text/css">
			.ui-datepicker{font-size:10px} 
		</style>
	</head>
    <h:body>
		<ui:composition template="/admin/template.xhtml">		    			
		<p:panel header="Hráči">	
			<h:panelGrid columns="2">
				<p:panel header="Administrace hráčů" style="min-width:500px;min-height: 847px;">
					<h:panelGrid columns="1">	
							<p:panel header="Výběr týmu" style="min-width:500px;">	
							<h:form>	
								<h:panelGrid columns="2">
									<h:panelGroup>
										<h:outputText value="Sezóna : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="seasonSelect" value="#{searchPlayerBean.selectedSeasonName}" style="width: 150px" >  
							                <f:selectItem  itemLabel="Vyberte sezónu" itemValue="" />  
							                <f:selectItems value="#{searchPlayerBean.seasonNamesList}" />
							                <p:ajax  update="competionSelect" listener="#{searchPlayerBean.handleSeasonChange}" /> 
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>		            			
									<h:panelGroup>
										<h:outputText value="Soutěž : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="competionSelect" value="#{searchPlayerBean.selectedCompetionName}" style="width: 150px" >  
							                <f:selectItem itemLabel="Vyberte soutěž" itemValue="" />  
							                <f:selectItems value="#{searchPlayerBean.competionNameList}" />
							                <p:ajax  update="teamSelect" listener="#{searchPlayerBean.handleTeamChange}" /> 
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup> 
									<h:panelGroup>
										<h:outputText value="Tým : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="teamSelect" value="#{searchPlayerBean.selectedTeamName}" style="width: 150px" >  
							                <f:selectItem itemLabel="Vyberte soutěž" itemValue="" />  
							                <f:selectItems value="#{searchPlayerBean.teamNameList}" />
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>  			            			           			
			            			<p:commandButton value="Hledej"  actionListener="#{searchPlayerBean.fillPlayerList}" update=":detailSouteze,:addCompetionForm,:growl"/>		            			
			            		</h:panelGrid>
			            	</h:form>		
		            		</p:panel>
		            		<p:panel>            			
	            				<h:form id="detailSouteze" >
									<p:dataTable id="playerTable" var="player" value="#{searchPlayerBean.playerList}" rowKey="#{player.id}"  selection="#{searchPlayerBean.selectedPlayer}" emptyMessage="Žádní hráči nenalazeny" selectionMode="single" tableStyle="min-width:300px;">
								        <f:facet name="header">
											<c:if test="#{searchPlayerBean.selectedCompetionName != '' and searchPlayerBean.selectedSeasonName != '' and searchPlayerBean.selectedTeamName != ''}">
											<h:outputText value="Seznam hráčů v soutěži "/>
											<h:outputText value="#{searchPlayerBean.selectedCompetionName}"/>
											<h:outputText value=" v sezóně "/>
											<h:outputText value="#{searchPlayerBean.selectedSeasonName}"/>
											<h:outputText value=" v týmu "/>
											<h:outputText value="#{searchPlayerBean.selectedTeamName}"/>
											</c:if>
								        </f:facet>
								        <p:column>  
								            <h:outputText value="#{player.firstname}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.surname}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.birthDate}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.position}" />  
								        </p:column>
								        <p:column>  
								            <h:outputText value="#{player.squadNr}" />  
								        </p:column>
								        <f:facet name="footer">  
							                <c:if test="#{searchPlayerBean.selectedCompetionName != '' and searchPlayerBean.selectedSeasonName != '' and searchPlayerBean.selectedTeamName != ''}">
							              		  <p:commandButton  icon="ui-icon-document" value="přidat hráče"  update=":form" oncomplete="competionAddDialog.show()"/>
							         	     	  <p:commandButton icon="ui-icon-pencil" value="editace" update=":editPlayer" oncomplete="editPlayerDialog.show()"/>
							         	     	  <p:commandButton  icon="ui-icon-close" value="odebrat hráče" actionListener="#{searchPlayerBean.deletePlayerFromTeam}" update="detailSouteze,:addCompetionForm,:growl"/>         
					       					</c:if>
					       				</f:facet> 
						  	        </p:dataTable>
					  	        </h:form>
					  	        <p:dialog id="dialogAddCompetion" header="Přidat hráče do týmu" widgetVar="competionAddDialog" resizable="false" width="300" showEffect="clip" hideEffect="fold">  
							      	 <h:form id="addCompetionForm">   
							      	    <h:panelGrid columns="1" cellpadding="4">
											<p:dataTable var="player" widgetVar="teamsAddTable" value="#{searchPlayerBean.playerListAdd}"  paginatorAlwaysVisible="false" paginatorPosition="bottom"  paginator="true" rows="7" rowKey="#{player.id}"  selection="#{searchPlayerBean.selectedPlayerAdd}" selectionMode="single"  filteredValue="#{searchTeamBean.filteredPlayers}" emptyMessage="Žádný hráč nenalezen" tableStyle="min-width:300px;">
										        <f:facet name="header">
													<p:outputPanel>  
									            	      <h:outputText value="Hledat hráče: " />  
									           		   	  <p:inputText id="globalFilter" onkeyup="teamsAddTable.filter()" style="width:150px" />  
									           		 </p:outputPanel>  
										        </f:facet>
										        <p:column filterBy="#{player.firstname}" filterStyle="display:none">  
										            <h:outputText value="#{player.firstname}" />  
										        </p:column>
										        <p:column filterBy="#{player.surname}" filterStyle="display:none">  
										            <h:outputText value="#{player.surname}" />  
										        </p:column>
										        <p:column filterBy="#{player.birthDate}" filterStyle="display:none">  
										            <h:outputText value="#{player.birthDate}" />  
										        </p:column>   
					  	   				 	</p:dataTable>
					  	   				 	 <h:panelGrid columns="2" cellpadding="4">
						      	      			 <h:outputText value="Pozice:" />    						      
							          			 <p:selectOneMenu id="competionSelect" value="#{searchPlayerBean.position}" style="width: 150px" >  
							          			      <f:selectItem itemLabel="Vyberte pozici" itemValue="" />  
							         			      <f:selectItems value="#{searchPlayerBean.positionList}" />
				            					</p:selectOneMenu>	
							          			 <h:outputText value="Číslo drezu:" />    						      
							          			 <p:inputMask value="#{searchPlayerBean.squadNr}" mask="9*" style="width:50px"/>     	 
						        			</h:panelGrid> 
					  	   				 	<p:commandButton value="Přidat" actionListener="#{searchPlayerBean.addPlayerToTeam}" update=":detailSouteze,:growl,:addCompetionForm" oncomplete="competionAddDialog.hide()"/> 
							        	</h:panelGrid>
							         </h:form>	
								</p:dialog>
								<p:dialog id="editPlayer" header="Editace hráče" widgetVar="editPlayerDialog" resizable="false" width="300" showEffect="clip" hideEffect="fold">  
							      	 <h:form>   
							      	    <h:panelGrid id="display" columns="2" cellpadding="4">
							      	       <h:outputText value="Jméno:" />    						      
								           <h:outputText value="#{searchPlayerBean.selectedPlayer.firstname}"/>  
							      	       <h:outputText value="Příjmení:" />    						      
								           <h:outputText value="#{searchPlayerBean.selectedPlayer.surname}"/>
							      	       <h:outputText value="Datum narození:" />
							      	       <h:outputText value="#{searchPlayerBean.selectedPlayer.birthDate}"/>
							      	       <h:outputText value="Pozice:" />    						      
								           <p:selectOneMenu id="competionSelect" value="#{searchPlayerBean.selectedPlayer.position}" style="width: 150px" >  
								          	      <f:selectItem itemLabel="Vyberte pozici" itemValue="" />  
								         	      <f:selectItems value="#{searchPlayerBean.positionList}" />
					            			</p:selectOneMenu>
					            			<h:outputText value="Číslo drezu:" />    						      
								            <p:inputMask value="#{searchPlayerBean.selectedPlayer.squadNr}" mask="9*" style="width:50px"/>     	  		     						      							             							             	 
							        	</h:panelGrid> 
							        	<p:commandButton value="Ulož změny"  actionListener="#{searchPlayerBean.updatePlayer}" update=":detailSouteze,:growl,:addCompetionForm" oncomplete="editPlayerDialog.hide()"/> 
							        </h:form>	
								 </p:dialog>	              		    
							</p:panel>            			           		    	  
					</h:panelGrid>
				</p:panel>
				<p:panel header="Editace hráčů" style="min-height: 500px;">   
				   <h:form id="form">	
					    	<p:dataTable id="playerTable" var="player" widgetVar="playersTable" value="#{playerBean.playerList}"  paginatorAlwaysVisible="false" paginatorPosition="bottom"  paginator="true" rows="14" rowKey="#{player.id}"  selection="#{playerBean.selectedPlayer}" selectionMode="single"  filteredValue="#{playerBean.filteredPlayers}" emptyMessage="Žádný hráč nenalezen" tableStyle="min-width:300px;">
						        <f:facet name="header">
									<p:outputPanel>  
					            	      <h:outputText value="Hledat hráče: " />  
					           		   	  <p:inputText id="globalFilter" onkeyup="playersTable.filter()" style="width:150px" />  
					           		 </p:outputPanel>  
						        </f:facet>
						        <p:column headerText="Jméno" filterBy="#{player.firstname}" filterStyle="display:none">  
						            <h:outputText value="#{player.firstname}" />  
						        </p:column>
						        <p:column headerText="Příjmení" filterBy="#{player.surname}" filterStyle="display:none">  
						            <h:outputText value="#{player.surname}" />  
						        </p:column>
						        <p:column headerText="Datum narození" filterBy="#{player.birthDate}" filterStyle="display:none">  
						            <h:outputText value="#{player.birthDate}" />  
						        </p:column>						        						        
						        <f:facet name="footer">  
					            	<p:commandButton icon="ui-icon-pencil" value="editace" update=":dialog" oncomplete="competionDialog.show()"/>
					                <p:commandButton icon="ui-icon-document" value="nový"  oncomplete="competionNewDialog.show()"/>       
					       		</f:facet>     
					  	    </p:dataTable>
					</h:form>
					<p:dialog id="dialog" header="Editace hráče" widgetVar="competionDialog" resizable="false"  
					              width="300" showEffect="clip" hideEffect="fold">  
						      	 <h:form>   
						      	    <h:panelGrid id="display" columns="2" cellpadding="4">
						      	       <h:outputText value="Jméno:" />    						      
							           <h:inputText value="#{playerBean.selectedPlayer.firstname}" style="width:150px"/>  
						      	       <h:outputText value="Příjmení:" />    						      
							           <h:inputText value="#{playerBean.selectedPlayer.surname}" style="width:150px"/>
						      	       <h:outputText value="Datum narození:" />
						      	       <p:inputMask value="#{playerBean.selectedPlayer.birthDate}" mask="99.99.9999"/>	     						      							             							             	 
						        	</h:panelGrid> 
						        	<p:commandButton value="Ulož změny"  actionListener="#{playerBean.updatePlayer}" update=":form,:growl" oncomplete="competionDialog.hide()"/> 
						        </h:form>	
					 </p:dialog>
				     <p:dialog id="dialogNew" header="Nový hráč" widgetVar="competionNewDialog" resizable="false"  
					              width="300" showEffect="clip" hideEffect="fold">  
						      	 <h:form>   
						      	    <h:panelGrid id="display" columns="2" cellpadding="4">
						      	       <h:outputText value="Jméno:" />    						      
							           <h:inputText value="#{playerBean.firstname}" style="width:150px"/>  
						      	       <h:outputText value="Příjmení:" />    						      
							           <h:inputText value="#{playerBean.newPlayer.surname}" style="width:150px"/>
						      	       <h:outputText value="Datum narození:" />    						      
							           <p:inputMask value="#{playerBean.newPlayer.birthDate}" mask="99.99.9999"/>	 
						        	</h:panelGrid> 
						        	<p:commandButton value="Uložit hráče"  actionListener="#{playerBean.createPlayer}" update=":form,:dialogNew,:growl" oncomplete="competionNewDialog.hide()"/> 
						        </h:form>	
					</p:dialog>
				</p:panel>
			</h:panelGrid>
		</p:panel>			
		</ui:composition>	
	</h:body>
</html>